struct EL {int info; struct EL *left, *right;}; typedef struct EL Tree; typedef Tree *Ptree; struct EL1 {int info; struct EL1 *next;}; typedef struct EL1 Lista; typedef Lista *Plista; typedef enum {false, true} boolean; /*Scrivere una funzione che restituisca il valore massimo contenuto nei nodi di un albero.*/ int massimo(int a, int b, int c){ if(a>b){ if(a>c) return a;} else if(b>c) return b; else if(c>b) return c; } #define max3(a, b, c) (a > b ? (c > a ? c : a) : (c > b ? c : b) )\ int maxtree(Ptree tree){ int max_s, max_d; if(tree==NULL) return -1; max_s=maxtree(tree->left); max_d=maxtree(tree->right); return massimo(max_s, max_d, tree->info); } /* Scrivere una funzione che verifichi se due alberi binari sono uguali */ boolean check(Ptree t1, Ptree t2){ if(t1==NULL && t2==NULL) return true; if(t1==NULL || t2==NULL) return false; return((t1->info==t2->info) && check(t1->left, t2->left) && check(t1->right, t2->right)); } /* Scrivere una funzione che, dato un albero in input, inserisca in una lista solo i nodi di livello pari. */ void prosegui_pari(Ptree *tree, Plista **lis); void prosegui(Ptree *tree, Plista **lis){ if(tree!=NULL){ prosegui_pari(&(*tree)->left, lis); prosegui_pari(&(*tree)->right, lis); } } void prosegui_pari(Ptree *tree, Plista **lis){ Plista aux; if(tree!=NULL){ aux=malloc(sizeof(Lista)); aux->next=**lis; aux->info=(*tree)->info; **lis=aux; prosegui(&(*tree)->left, lis); prosegui(&(*tree)->right, lis); } } int main(){ // aggiungere stampe di cortesia ecc... return 0; }